Add tracing support for native method calls via Java FFM API#10718
Add tracing support for native method calls via Java FFM API#10718gh-worker-dd-mergequeue-cf854d[bot] merged 17 commits intomasterfrom
Conversation
BenchmarksStartupParameters
See matching parameters
SummaryFound 2 performance improvements and 1 performance regressions! Performance is the same for 61 metrics, 7 unstable metrics.
Startup time reports for insecure-bankgantt
title insecure-bank - global startup overhead: candidate=1.61.0-SNAPSHOT~ac00550bbb, baseline=1.61.0-SNAPSHOT~b7fb6fc123
dateFormat X
axisFormat %s
section tracing
Agent [baseline] (1.056 s) : 0, 1056181
Total [baseline] (8.887 s) : 0, 8887426
Agent [candidate] (1.062 s) : 0, 1061704
Total [candidate] (8.847 s) : 0, 8846920
section iast
Agent [baseline] (1.231 s) : 0, 1231193
Total [baseline] (9.534 s) : 0, 9534497
Agent [candidate] (1.231 s) : 0, 1231355
Total [candidate] (9.579 s) : 0, 9578871
gantt
title insecure-bank - break down per module: candidate=1.61.0-SNAPSHOT~ac00550bbb, baseline=1.61.0-SNAPSHOT~b7fb6fc123
dateFormat X
axisFormat %s
section tracing
crashtracking [baseline] (1.195 ms) : 0, 1195
crashtracking [candidate] (1.198 ms) : 0, 1198
BytebuddyAgent [baseline] (629.029 ms) : 0, 629029
BytebuddyAgent [candidate] (633.052 ms) : 0, 633052
AgentMeter [baseline] (29.322 ms) : 0, 29322
AgentMeter [candidate] (29.383 ms) : 0, 29383
GlobalTracer [baseline] (256.754 ms) : 0, 256754
GlobalTracer [candidate] (257.705 ms) : 0, 257705
AppSec [baseline] (31.761 ms) : 0, 31761
AppSec [candidate] (31.781 ms) : 0, 31781
Debugger [baseline] (59.738 ms) : 0, 59738
Debugger [candidate] (59.387 ms) : 0, 59387
Remote Config [baseline] (592.281 µs) : 0, 592
Remote Config [candidate] (607.529 µs) : 0, 608
Telemetry [baseline] (8.094 ms) : 0, 8094
Telemetry [candidate] (8.182 ms) : 0, 8182
Flare Poller [baseline] (3.519 ms) : 0, 3519
Flare Poller [candidate] (4.336 ms) : 0, 4336
section iast
crashtracking [baseline] (1.225 ms) : 0, 1225
crashtracking [candidate] (1.199 ms) : 0, 1199
BytebuddyAgent [baseline] (799.077 ms) : 0, 799077
BytebuddyAgent [candidate] (799.655 ms) : 0, 799655
AgentMeter [baseline] (11.426 ms) : 0, 11426
AgentMeter [candidate] (11.35 ms) : 0, 11350
GlobalTracer [baseline] (248.363 ms) : 0, 248363
GlobalTracer [candidate] (248.517 ms) : 0, 248517
IAST [baseline] (25.528 ms) : 0, 25528
IAST [candidate] (25.445 ms) : 0, 25445
AppSec [baseline] (26.667 ms) : 0, 26667
AppSec [candidate] (26.477 ms) : 0, 26477
Debugger [baseline] (67.667 ms) : 0, 67667
Debugger [candidate] (63.75 ms) : 0, 63750
Remote Config [baseline] (523.775 µs) : 0, 524
Remote Config [candidate] (514.116 µs) : 0, 514
Telemetry [baseline] (10.638 ms) : 0, 10638
Telemetry [candidate] (13.642 ms) : 0, 13642
Flare Poller [baseline] (3.878 ms) : 0, 3878
Flare Poller [candidate] (4.569 ms) : 0, 4569
Startup time reports for petclinicgantt
title petclinic - global startup overhead: candidate=1.61.0-SNAPSHOT~ac00550bbb, baseline=1.61.0-SNAPSHOT~b7fb6fc123
dateFormat X
axisFormat %s
section tracing
Agent [baseline] (1.07 s) : 0, 1069535
Total [baseline] (11.065 s) : 0, 11064501
Agent [candidate] (1.064 s) : 0, 1063891
Total [candidate] (11.008 s) : 0, 11007505
section appsec
Agent [baseline] (1.257 s) : 0, 1256910
Total [baseline] (11.228 s) : 0, 11228128
Agent [candidate] (1.266 s) : 0, 1265858
Total [candidate] (11.125 s) : 0, 11125190
section iast
Agent [baseline] (1.236 s) : 0, 1236087
Total [baseline] (11.399 s) : 0, 11398628
Agent [candidate] (1.236 s) : 0, 1235721
Total [candidate] (11.37 s) : 0, 11370009
section profiling
Agent [baseline] (1.196 s) : 0, 1196433
Total [baseline] (11.109 s) : 0, 11109381
Agent [candidate] (1.192 s) : 0, 1192462
Total [candidate] (11.023 s) : 0, 11023358
gantt
title petclinic - break down per module: candidate=1.61.0-SNAPSHOT~ac00550bbb, baseline=1.61.0-SNAPSHOT~b7fb6fc123
dateFormat X
axisFormat %s
section tracing
crashtracking [baseline] (1.217 ms) : 0, 1217
crashtracking [candidate] (1.193 ms) : 0, 1193
BytebuddyAgent [baseline] (635.842 ms) : 0, 635842
BytebuddyAgent [candidate] (633.343 ms) : 0, 633343
AgentMeter [baseline] (29.628 ms) : 0, 29628
AgentMeter [candidate] (29.427 ms) : 0, 29427
GlobalTracer [baseline] (259.114 ms) : 0, 259114
GlobalTracer [candidate] (257.79 ms) : 0, 257790
AppSec [baseline] (32.322 ms) : 0, 32322
AppSec [candidate] (31.911 ms) : 0, 31911
Debugger [baseline] (61.183 ms) : 0, 61183
Debugger [candidate] (60.319 ms) : 0, 60319
Remote Config [baseline] (603.295 µs) : 0, 603
Remote Config [candidate] (585.233 µs) : 0, 585
Telemetry [baseline] (9.657 ms) : 0, 9657
Telemetry [candidate] (8.151 ms) : 0, 8151
Flare Poller [baseline] (3.608 ms) : 0, 3608
Flare Poller [candidate] (5.07 ms) : 0, 5070
section appsec
crashtracking [baseline] (1.198 ms) : 0, 1198
crashtracking [candidate] (1.206 ms) : 0, 1206
BytebuddyAgent [baseline] (663.459 ms) : 0, 663459
BytebuddyAgent [candidate] (666.925 ms) : 0, 666925
AgentMeter [baseline] (12.19 ms) : 0, 12190
AgentMeter [candidate] (12.237 ms) : 0, 12237
GlobalTracer [baseline] (260.4 ms) : 0, 260400
GlobalTracer [candidate] (260.208 ms) : 0, 260208
IAST [baseline] (24.693 ms) : 0, 24693
IAST [candidate] (24.42 ms) : 0, 24420
AppSec [baseline] (179.069 ms) : 0, 179069
AppSec [candidate] (185.229 ms) : 0, 185229
Debugger [baseline] (66.956 ms) : 0, 66956
Debugger [candidate] (66.405 ms) : 0, 66405
Remote Config [baseline] (627.411 µs) : 0, 627
Remote Config [candidate] (652.713 µs) : 0, 653
Telemetry [baseline] (8.406 ms) : 0, 8406
Telemetry [candidate] (8.451 ms) : 0, 8451
Flare Poller [baseline] (3.609 ms) : 0, 3609
Flare Poller [candidate] (3.625 ms) : 0, 3625
section iast
crashtracking [baseline] (1.232 ms) : 0, 1232
crashtracking [candidate] (1.208 ms) : 0, 1208
BytebuddyAgent [baseline] (801.231 ms) : 0, 801231
BytebuddyAgent [candidate] (802.008 ms) : 0, 802008
AgentMeter [baseline] (11.566 ms) : 0, 11566
AgentMeter [candidate] (11.428 ms) : 0, 11428
GlobalTracer [baseline] (249.755 ms) : 0, 249755
GlobalTracer [candidate] (249.273 ms) : 0, 249273
IAST [baseline] (25.634 ms) : 0, 25634
IAST [candidate] (25.482 ms) : 0, 25482
AppSec [baseline] (26.652 ms) : 0, 26652
AppSec [candidate] (26.516 ms) : 0, 26516
Debugger [baseline] (69.314 ms) : 0, 69314
Debugger [candidate] (64.133 ms) : 0, 64133
Remote Config [baseline] (531.763 µs) : 0, 532
Remote Config [candidate] (523.584 µs) : 0, 524
Telemetry [baseline] (10.238 ms) : 0, 10238
Telemetry [candidate] (14.497 ms) : 0, 14497
Flare Poller [baseline] (3.682 ms) : 0, 3682
Flare Poller [candidate] (3.89 ms) : 0, 3890
section profiling
crashtracking [baseline] (1.191 ms) : 0, 1191
crashtracking [candidate] (1.201 ms) : 0, 1201
BytebuddyAgent [baseline] (690.654 ms) : 0, 690654
BytebuddyAgent [candidate] (691.105 ms) : 0, 691105
AgentMeter [baseline] (9.092 ms) : 0, 9092
AgentMeter [candidate] (9.118 ms) : 0, 9118
GlobalTracer [baseline] (217.318 ms) : 0, 217318
GlobalTracer [candidate] (215.29 ms) : 0, 215290
AppSec [baseline] (32.717 ms) : 0, 32717
AppSec [candidate] (32.206 ms) : 0, 32206
Debugger [baseline] (66.754 ms) : 0, 66754
Debugger [candidate] (66.006 ms) : 0, 66006
Remote Config [baseline] (576.554 µs) : 0, 577
Remote Config [candidate] (577.212 µs) : 0, 577
Telemetry [baseline] (7.858 ms) : 0, 7858
Telemetry [candidate] (7.818 ms) : 0, 7818
Flare Poller [baseline] (3.557 ms) : 0, 3557
Flare Poller [candidate] (3.495 ms) : 0, 3495
ProfilingAgent [baseline] (95.037 ms) : 0, 95037
ProfilingAgent [candidate] (94.542 ms) : 0, 94542
Profiling [baseline] (95.604 ms) : 0, 95604
Profiling [candidate] (95.11 ms) : 0, 95110
LoadParameters
See matching parameters
SummaryFound 0 performance improvements and 3 performance regressions! Performance is the same for 17 metrics, 16 unstable metrics.
Request duration reports for petclinicgantt
title petclinic - request duration [CI 0.99] : candidate=1.61.0-SNAPSHOT~ac00550bbb, baseline=1.61.0-SNAPSHOT~b7fb6fc123
dateFormat X
axisFormat %s
section baseline
no_agent (17.311 ms) : 17137, 17485
. : milestone, 17311,
appsec (18.669 ms) : 18479, 18859
. : milestone, 18669,
code_origins (18.002 ms) : 17824, 18180
. : milestone, 18002,
iast (18.222 ms) : 18040, 18404
. : milestone, 18222,
profiling (19.529 ms) : 19333, 19724
. : milestone, 19529,
tracing (17.819 ms) : 17642, 17996
. : milestone, 17819,
section candidate
no_agent (18.092 ms) : 17910, 18274
. : milestone, 18092,
appsec (18.702 ms) : 18511, 18893
. : milestone, 18702,
code_origins (17.874 ms) : 17699, 18050
. : milestone, 17874,
iast (17.883 ms) : 17703, 18063
. : milestone, 17883,
profiling (19.705 ms) : 19502, 19907
. : milestone, 19705,
tracing (17.728 ms) : 17553, 17903
. : milestone, 17728,
Request duration reports for insecure-bankgantt
title insecure-bank - request duration [CI 0.99] : candidate=1.61.0-SNAPSHOT~ac00550bbb, baseline=1.61.0-SNAPSHOT~b7fb6fc123
dateFormat X
axisFormat %s
section baseline
no_agent (1.217 ms) : 1205, 1228
. : milestone, 1217,
iast (3.318 ms) : 3271, 3366
. : milestone, 3318,
iast_FULL (6.022 ms) : 5960, 6084
. : milestone, 6022,
iast_GLOBAL (3.558 ms) : 3499, 3617
. : milestone, 3558,
profiling (2.153 ms) : 2135, 2172
. : milestone, 2153,
tracing (1.857 ms) : 1842, 1872
. : milestone, 1857,
section candidate
no_agent (1.219 ms) : 1207, 1231
. : milestone, 1219,
iast (3.351 ms) : 3302, 3400
. : milestone, 3351,
iast_FULL (5.957 ms) : 5896, 6018
. : milestone, 5957,
iast_GLOBAL (3.754 ms) : 3691, 3818
. : milestone, 3754,
profiling (2.346 ms) : 2323, 2369
. : milestone, 2346,
tracing (1.907 ms) : 1891, 1924
. : milestone, 1907,
DacapoParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 10 metrics, 2 unstable metrics. Execution time for tomcatgantt
title tomcat - execution time [CI 0.99] : candidate=1.61.0-SNAPSHOT~ac00550bbb, baseline=1.61.0-SNAPSHOT~b7fb6fc123
dateFormat X
axisFormat %s
section baseline
no_agent (1.496 ms) : 1484, 1508
. : milestone, 1496,
appsec (3.856 ms) : 3630, 4082
. : milestone, 3856,
iast (2.279 ms) : 2209, 2349
. : milestone, 2279,
iast_GLOBAL (2.331 ms) : 2261, 2401
. : milestone, 2331,
profiling (2.539 ms) : 2377, 2700
. : milestone, 2539,
tracing (2.111 ms) : 2057, 2165
. : milestone, 2111,
section candidate
no_agent (1.494 ms) : 1482, 1505
. : milestone, 1494,
appsec (3.835 ms) : 3612, 4058
. : milestone, 3835,
iast (2.291 ms) : 2221, 2361
. : milestone, 2291,
iast_GLOBAL (2.336 ms) : 2266, 2406
. : milestone, 2336,
profiling (2.13 ms) : 2073, 2187
. : milestone, 2130,
tracing (2.098 ms) : 2044, 2151
. : milestone, 2098,
Execution time for biojavagantt
title biojava - execution time [CI 0.99] : candidate=1.61.0-SNAPSHOT~ac00550bbb, baseline=1.61.0-SNAPSHOT~b7fb6fc123
dateFormat X
axisFormat %s
section baseline
no_agent (14.875 s) : 14875000, 14875000
. : milestone, 14875000,
appsec (15.093 s) : 15093000, 15093000
. : milestone, 15093000,
iast (18.387 s) : 18387000, 18387000
. : milestone, 18387000,
iast_GLOBAL (17.993 s) : 17993000, 17993000
. : milestone, 17993000,
profiling (14.995 s) : 14995000, 14995000
. : milestone, 14995000,
tracing (14.749 s) : 14749000, 14749000
. : milestone, 14749000,
section candidate
no_agent (15.001 s) : 15001000, 15001000
. : milestone, 15001000,
appsec (14.923 s) : 14923000, 14923000
. : milestone, 14923000,
iast (18.149 s) : 18149000, 18149000
. : milestone, 18149000,
iast_GLOBAL (17.736 s) : 17736000, 17736000
. : milestone, 17736000,
profiling (14.954 s) : 14954000, 14954000
. : milestone, 14954000,
tracing (14.879 s) : 14879000, 14879000
. : milestone, 14879000,
|
| // this module is not opened by default hence we are inlining this code into the target to | ||
| // circumvent this limitation | ||
| try { | ||
| final MethodHandle mh = |
There was a problem hiding this comment.
This could be cached by class. However, I don't expect a ton of call to loadLibrary. So IMHO this can be acceptable and kept in this shape
mcculls
left a comment
There was a problem hiding this comment.
Main issue to address before this can be merged is whether we can further minimize the startup cost, which mostly relates to adding jdk.internal.loader.* to the allow list for instrumentation.
705e3c3 to
b30744c
Compare
@mcculls Yes, that was a bit naive on my side—not narrowing the package pulled in more than expected. I’ve now limited it to the minimal set of classes, and the startup tests look much better. Thanks for pushing on that. |
...java-lang-22.0/src/main/java/datadog/trace/instrumentation/java/lang/jdk22/FFMApiModule.java
Outdated
Show resolved
Hide resolved
mcculls
left a comment
There was a problem hiding this comment.
LGTM, thanks for narrowing the filter
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
What Does This Do
Introduces automatic tracing of native (downcall) method invocations made through the Java Foreign Function & Memory (FFM) API (available since JDK 22).
trace.native.methodsthat follows the samelibrary[method1,method2]/library[*]format astrace.methods, letting users opt-in to tracing specific native calls.Linker.downcallHandle(MemorySegment, ...)to wrap the producedMethodHandlewith span creation/finalization logic built using MethodHandles.tryFinally + MethodHandles.foldArguments — zero overhead when the handle is not traced.trace.native, componenttrace-ffm.lib_name.symbol_name. The lib_name is lowercased. Does not contain path or extensionA note about the library name used to resolve syscalls. Java use internally
libsyslookup. I don't know how portable is it. If yes we can strip this prefix. However, today, to say I'd like to tracestrlenfrom the libc the user needs to say that want to tracelibsyslookup[strlen]Motivation
R&D week
Additional Notes
Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: [PROJ-IDENT]
Note: Once your PR is ready to merge, add it to the merge queue by commenting
/merge./merge -ccancels the queue request./merge -f --reason "reason"skips all merge queue checks; please use this judiciously, as some checks do not run at the PR-level. For more information, see this doc.